a11y: Avoid signal emission during cache population
authorEmmanuele Bassi <ebassi@gnome.org>
Thu, 21 Jan 2021 16:31:28 +0000 (16:31 +0000)
committerEmmanuele Bassi <ebassi@gnome.org>
Thu, 21 Jan 2021 16:40:57 +0000 (16:40 +0000)
If we're responding to a request to get all the cached items, there's no
need to emit signals when adding an ATContext to the cache.

gtk/a11y/gtkatspicache.c

index 10736341e51cb8a9553990037d57377d86bc0398..e1c7b5d628a3ca7056343bdac5b5c44c77b5376a 100644 (file)
@@ -58,6 +58,9 @@ struct _GtkAtSpiCache
 
   /* HashTable<GtkAtSpiContext, str> */
   GHashTable *contexts_to_path;
+
+  /* Re-entrancy guard */
+  gboolean in_get_items;
 };
 
 enum
@@ -250,10 +253,17 @@ handle_cache_method (GDBusConnection       *connection,
     {
       GVariantBuilder builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("(" GET_ITEMS_SIGNATURE ")"));
 
+      /* Prevent the emission os signals while collecting accessible
+       * objects as the result of walking the accessible tree
+       */
+      self->in_get_items = TRUE;
+
       g_variant_builder_open (&builder, G_VARIANT_TYPE (GET_ITEMS_SIGNATURE));
       collect_cached_objects (self, &builder);
       g_variant_builder_close (&builder);
 
+      self->in_get_items = FALSE;
+
       g_dbus_method_invocation_return_value (invocation, g_variant_builder_end (&builder));
     }
 }
@@ -371,7 +381,11 @@ gtk_at_spi_cache_add_context (GtkAtSpiCache   *self,
 
   GTK_NOTE (A11Y, g_message ("Adding context '%s' to cache", path_key));
 
-  emit_add_accessible (self, context);
+  /* GetItems is safe from re-entrancy, but we still don't want to
+   * emit an unnecessary signal while we're collecting ATContexts
+   */
+  if (!self->in_get_items)
+    emit_add_accessible (self, context);
 }
 
 void